import Request from '@/request'
import type { Response, PageParams } from '@/types/global'
import type { HouseList } from '@/types/homePage'
import type { actItem } from '@/types/activityPage'
import type { VoteItem } from '@/types/others'

export const gethouse = (data: PageParams): Promise<Response<HouseList>> => {
  return Request.getToken(
    '/houseinfo/',
    { Authorization: data.Authorization },
    data.Authorization
  )
}

export const houseList = (data: PageParams): Promise<Response<HouseList[]>> => {
  return Request.get('/houseList/', data)
}

export const activeList = (data: {
  state: number
}): Promise<Response<actItem[]>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/get_activity/', data, token)
}

export const activeInfo = (activeId: number): Promise<Response<actItem>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/activity_info', { id: activeId }, token)
}

export const houseInfoI = (id: number): Promise<Response<HouseList>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/houseinfo/', { id }, token)
}

export const voteListItem = (data: {
  state: number
}): Promise<Response<VoteItem[]>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/getVoteList/', data, token)
}

export const voteInfos = (voteId: number): Promise<Response<VoteItem>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/vote_info/', { id: voteId }, token)
}

export const normList = (id: number): Promise<Response<any[]>> => {
  return Request.get('/normList/', { id })
}

export const normInfo = (data: {
  id: number
  normid?: number
  noticeid?: number
}): Promise<Response<any>> => {
  return Request.get('/norm_info/', data)
}

export const rapir = (data: any): Promise<Response<any>> => {
  const token = uni.getStorageSync('token')
  return Request.postToken('/rapir/', data, token)
}

export const repiarLis = (): Promise<Response<HouseList>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/reportList/', {}, token)
}

export const userInfo = (): Promise<Response<any>> => {
  const token = uni.getStorageSync('token')
  return Request.getToken('/user_info/', {}, token)
}

export const compair = (data: any): Promise<Response<any>> => {
  const token = uni.getStorageSync('token')
  return Request.postTokenNotImg('/complain', data, token)
}

export const voteadd = (data: any): Promise<Response<any>> => {
  const token = uni.getStorageSync('token')
  return Request.postTokenNotImg('/addVote', data, token)
}

export const devise = (data: any): Promise<Response<any>> => {
  const token = uni.getStorageSync('token')
  return Request.postTokenHead('/devise', data, token)
}
